import Api from './api.js'
import request from '@/utils/request'
import axios from 'axios'
// import {download_excel} from "@/utils/fileExport.js"

// 超期会议
export const DelateMetting = {
    // 根据主键Id异步获取信息(编辑回显行数据)
    GetLoadAsync(_id) {
        return request.get(Api.GetLoadAsync + '?id=' + _id + '&operation=MEETING_INFORMATION')
    },
    // 分页获取超期会议信息
    GetPageAsync(_data) {
        return request.post(Api.GetPageAsync, _data)
    },
    // 分页获取超期会议信息
    InsertAsync(_data) {
        return request.post(Api.InsertAsync, _data)
    },
    // 异步修改超级会议信息
    UpdateAsync(_data) {
        return request.post(Api.UpdateAsync, _data)
    },
    //  /api/GetFeedBackOverTime/{feedBackNumber}
    // 获取反馈超期信息
    GetFeedBackOverTime(_data) {
        return request.get(Api.GetFeedBackOverTime + '/' + _data)
    },
    // 获取版本 会议列表
    GetVersionMeetingList(meetingId, version) {
        return request.get(Api.GetVersionMeetingList + '/' + meetingId + '/' + version)
    },
    // 获取 反馈会议的 任务反馈详情
    GetVersionMeetingInfo(_id, version) {
        return request.get(Api.GetVersionMeetingInfo + _id + '/' + version)
    },
    // 获取任务超期信息
    GetTaskOverTime(taskNumber) {
        return request.get(Api.GetTaskOverTime + taskNumber)
    },
    // 保存关联超期会议
    // /api/OverTimeMeeting/SaveAssociate
    SaveAssociate(_data) {
        return request.post(Api.SaveAssociate, _data)
    },
    // 删除反馈、任务超期会议
    Remove(_id, version) {
        return request.post(Api.Remove + _id + '/' + version)
    },
    // 推送
    PushSeverelyOverdue(_id) {
        return request.post(Api.PushSeverelyOverdue + _id)
    },
    // 获取邮件
    GetEmail(meetingId, version) {
        return request.get(Api.GetEmail + meetingId + '/' + version)
    },
    // 发送邮件
    SendEmail(_data) {
        return request.post(Api.SendEmail, _data)
    },
    // 批量抓取
    GenerateMeeting() {
        return request.get(Api.GenerateMeeting)
    },
    // 会议记录
    GetMeetingRecord(mettingId, type) {
        return request.get(Api.GetMeetingRecord + `/${mettingId}/${type}`)
    },
    // 添加会议记录
    AddMettingRecord(_data) {
        return request.post(Api.AddMettingRecord, _data)
    },
    // 删除会议记录
    DeleteMettingRecord(_id) {
        return request.post(Api.DeleteMettingRecord + _id)
    },
    // V1V2导出查询结果
    ExportMetting(meetingId, version) {
    // return request.get(Api.UpdateMettingRecord+meetingId+'/'+version);
    // download_excel(Api.UpdateMettingRecord+meetingId+'/'+version,filesname)

        axios({
            method: 'post',
            url: process.env.VUE_APP_BASE_API + Api.ExportMetting + meetingId + '/' + version,
            responseType: 'blob',
            headers: {
                token: JSON.parse(sessionStorage.getItem('USERINFO')).token
            }
        }).then(res => {
            const objectUrl = URL.createObjectURL(res.data)
            const a = document.createElement('a')
            document.body.appendChild(a)
            a.href = objectUrl
            console.log(res)
            const filenames = decodeURIComponent(res.headers['filename'])
            a.download = filenames
            a.click()
            window.URL.revokeObjectURL(objectUrl)
        })
    },
    // 导出会议记录
    ExportMettingRecord(meetingId) {
    // return request.get(Api.UpdateMettingRecord+meetingId+'/'+version);
    // download_excel(Api.UpdateMettingRecord+meetingId+'/'+version,filesname)

        axios({
            method: 'post',
            url: process.env.VUE_APP_BASE_API + Api.ExportMettingRecord + `/${meetingId}`,
            responseType: 'blob',
            headers: {
                token: JSON.parse(sessionStorage.getItem('USERINFO')).token
            }
        }).then(res => {
            const objectUrl = URL.createObjectURL(res.data)
            const a = document.createElement('a')
            document.body.appendChild(a)
            const code = res.headers['filename']
            const d = new Date()
            const time =
        '会议记录' +
        d.getFullYear() +
        (d.getMonth() + 1) +
        d.getDate() +
        d.getHours() +
        d.getMinutes() +
        d.getSeconds() +
        '.xlsx'
            console.log('code', code)
            a.href = objectUrl
            a.download = time
            a.click()
            window.URL.revokeObjectURL(objectUrl)
        })
    },
    replyMeeting(_data) {
        return request.post(Api.replyMeeting, _data)
    },
    publishMeeting(meetingId) {
        return request.get(Api.publishMeeting + '/' + meetingId)
    },
    // V3子任务表格
    meetingRecordTask(meetingId, feedBackNumber) {
        return request.get(Api.meetingRecordTask + `/${meetingId}/${feedBackNumber}`)
    },
    // V3子任务表格 删除
    removeMeetingRecordTask(meetingRecordId) {
        return request.post(Api.removeMeetingRecordTask + `/${meetingRecordId}`)
    },
    // V3子任务表格 新增
    createMeetingRecordTask(data) {
        return request.post(Api.createMeetingRecordTask, data)
    },
    updateMeetingRecordTask(data) {
        return request.post(Api.updateMeetingRecordTask, data)
    },
    updateMeetingRecordFeedBack(data) {
        return request.post(Api.updateMeetingRecordFeedBack, data)
    },
    publishMeetingv3(data) {
        return request.post(Api.publishMeetingv3 + `/${data}`)
    },
    sendV3(data) {
        return request.post(Api.sendV3 + `/${data}`)
    }
}
